package com.resataurant.Controller.Admin;

import com.resataurant.Entity.User;
import com.resataurant.Service.AdminService;
import com.resataurant.Service.Impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "CusManageServlet", value = "/CusManageServlet")
public class CusManageServlet extends HttpServlet {

    AdminService adminService=new AdminServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");//防止中文乱码

        String UserName=request.getParameter("UserName");//获取餐品名称
        System.out.println(UserName+"-------------------");
        List<User> list=null;
        if(UserName==null || UserName.isEmpty()){
            list=adminService.searchUser();
        }
        else{
            list=adminService.searchUser(UserName);
        }
        String res="1";
        request.getSession().setAttribute("list",list);
        request.getSession().setAttribute("res",res);
        System.out.println(request.getSession().getAttribute("res"));
        for (User user : list) {
            System.out.println(user.getUsername());
            System.out.println(user.getUsername());
        }
        request.getRequestDispatcher("searchResult.jsp").forward(request,response);
    }
}
